<?php
	header("Content-Type: application/vnd.ms-word;");
	header("Content-Disposition: attachment; filename=TKTHBM_".$_GET['mabm'].".doc");
	echo "<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>";
	include_once('Configs/database.php');
	include_once('Models/NhatKi.php');
	include_once('Models/LopHocPhan.php');
	include_once('Models/BoMon.php');
	include_once('Models/Khoa.php');
	$nhatki = new NhatKi();;
	$lophp = new LopHocPhan();
	
	$db = new database();
	$namhoc = $_GET['namhoc'];
	$hocki = $_GET['hocki'];
	//$maso = $_GET['maso'];
	$mabm = $_GET['mabm'];
	$query = "select distinct a.maso, concat(holot, ' ', ten) as hoten, tenhp,kihieu,sotc,a.malophp,siso,a.mahp,manhom,sotietlithuyet,sotietthuchanh ";
	$query .= "from LopHocPhan a, HocPhan b, CanBo c,CanBoGiangDay d ";
	$query .= "where hocki=".$hocki." and namhoc='".$namhoc."' and mabm='".$mabm."' ";
	$query .= "and a.mahp = b.mahp and a.maso = c.maso and c.maso = d.maso order by hoten ";
	$db->setQuery($query);
	//echo $db->getQuery();
	$result = $db->fetchAll();
	$bm = new BoMon();
	$bm->setMaBM($mabm);
	$resultbm = $bm->thongTinBM();
	$rowsbm = mysql_fetch_array($resultbm);
	$tenbm = $rowsbm['tenbm'];
	
	$khoa = new Khoa();
	$khoa->setMaKhoa($rowsbm['makhoa']);
	$resultkhoa = $khoa->thongTinKhoa();
	$rowskhoa = mysql_fetch_array($resultkhoa);
	$tenkhoa = $rowskhoa['tenkhoa'];
	
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>
<style type="text/css">
<!--
.style4 {font-family: tahoma}
.khung {
	border: medium solid #000000;
}
-->
</style>
</head>

<body>
<p align="center"><strong>THỐNG KÊ TỔNG HỢP CÔNG TÁC GIẢNG DẠY LỚP HỌC PHẦN </strong><br />
<span class="style4">HỌC KỲ: <b><?php echo $hocki?></b> - NĂM HỌC: <b><?php echo $namhoc?></b> </span></p>
<p align="left">Bộ Môn: <b><?php echo $tenbm?></b><br />

  Đơn vị (Khoa/Viện/TT): <b><?php echo $tenkhoa?></b> </span><br />
</p>
<table width="100%" border="0" align="center">
  <tr>
    <td width="52%"><strong>Bảng Thống Kê Tổng Hợp </strong></td>
    <td width="48%"><strong>Mẫu TH:1 (Dành cho Giảng Viên và Bộ môn) </strong></td>
  </tr>

</table>
<br />
<table width="100%" align="center"  cellpadding="0" cellspacing="0" style="border: 1px solid #686;" border="1">
  <tr>
    <td colspan="3" rowspan="3" align="center" valign="middle" bgcolor="#DAE9F3">TT Mã số Họ và tên GV </td>
    <td width="50" rowspan="3" align="center" valign="middle" bgcolor="#DAE9F3">MSHP</td>
    <td width="29" rowspan="3" align="center" valign="middle" bgcolor="#DAE9F3">Số Tín Chỉ </td>
    <td width="42" rowspan="3" align="center" valign="middle" bgcolor="#DAE9F3">MS lớp HP </td>

    <td width="35" rowspan="3" align="center" valign="middle" bgcolor="#DAE9F3">SS.sv</td>
    <td colspan="9" align="center" valign="middle" bgcolor="#DAE9F3">Khối lượng tiết giảng(G) </td>
    <td width="126" rowspan="2" align="center" valign="middle" bgcolor="#DAE9F3">Ghi Chú </td>
  </tr>
  <tr>
    <td colspan="3" align="center" valign="middle" bgcolor="#DAE9F3">Kế họach(G1) </td>

    <td colspan="3" align="center" valign="middle" bgcolor="#DAE9F3">Thực hiện(G2) </td>
    <td colspan="3" align="center" valign="middle" bgcolor="#DAE9F3">Khác biệt(G2-G1) </td>
  </tr>
  <tr>
    <td align="center" valign="middle" bgcolor="#DAE9F3">LT</td>
    <td align="center" valign="middle" bgcolor="#DAE9F3">TH</td>
    <td width="40" align="center" valign="middle" bgcolor="#DAE9F3">Tổng</td>

    <td width="30" align="center" valign="middle" bgcolor="#DAE9F3">LT </td>
    <td width="28" align="center" valign="middle" bgcolor="#DAE9F3">TH</td>
    <td width="31" align="center" valign="middle" bgcolor="#DAE9F3">Tổng</td>
    <td width="25" align="center" valign="middle" bgcolor="#DAE9F3">LT</td>
    <td width="23" align="center" valign="middle" bgcolor="#DAE9F3">TH</td>
    <td width="57" align="center" valign="middle" bgcolor="#DAE9F3">Tổng</td>

    <td width="126" align="center" valign="middle" bgcolor="#DAE9F3">&nbsp;</td>
  </tr>
  <tr>
    <td width="36" align="center" valign="middle" bgcolor="#DAE9F3">1</td>

    <td width="35" align="center" valign="middle" bgcolor="#DAE9F3">2</td>
    <td width="33" align="center" valign="middle" bgcolor="#DAE9F3">3</td>
    <td align="center" valign="middle" bgcolor="#DAE9F3">4</td>
    <td align="center" valign="middle" bgcolor="#DAE9F3">5</td>
    <td align="center" valign="middle" bgcolor="#DAE9F3">6</td>
    <td align="center" valign="middle" bgcolor="#DAE9F3">7</td>

    <td width="25" align="center" valign="middle" bgcolor="#DAE9F3">8</td>
    <td width="31" align="center" valign="middle" bgcolor="#DAE9F3">9</td>
    <td align="center" valign="middle" bgcolor="#DAE9F3">10</td>
    <td align="center" valign="middle" bgcolor="#DAE9F3">11</td>
    <td align="center" valign="middle" bgcolor="#DAE9F3">12</td>
    <td align="center" valign="middle" bgcolor="#DAE9F3">13</td>

    <td align="center" valign="middle" bgcolor="#DAE9F3">14</td>
    <td align="center" valign="middle" bgcolor="#DAE9F3">15</td>
    <td align="center" valign="middle" bgcolor="#DAE9F3">A 16 B </td>
    <td align="center" valign="middle" bgcolor="#DAE9F3">20</td>
  </tr>
   <?php
  	$i = 0;
	  while ($rows = mysql_fetch_array($result))
	  {	
		$lophp->setMaLopHP($rows['malophp']);
		$resultdsnhomth = $lophp->dsNhomThucHanh();
		
		//$nhatki->setMaLopHP($rows['malophp']);
		if ($rows['manhom']==1 || $rows['manhom']==3 )
		{
			$i++;
			$c = 2- $i%2;
  ?>
  <tr>
    <td align="center" valign="middle"  bgcolor="#DAE9F3"><?php echo $i?></td>

    <td align="center" valign="middle" ><?php echo $rows['maso']?></td>
    <td width="120" align="left" valign="middle" ><?php echo $rows['hoten']?></td>
    <td align="center" valign="middle" ><?php echo $rows['mahp']?></td>
    <td align="center" valign="middle" ><?php echo $rows['sotc']?></td>
    <td align="center" valign="middle" ><?php echo $rows['malophp']?></td>
    <td align="center" valign="middle" ><?php echo $rows['siso']?></td>
    <td align="center" valign="middle" ><?php echo $rows['sotietlithuyet']?></td>
    <td align="center" valign="middle" ><?php echo $lophp->soTietTHQuyChuanTheoKH();?></td>
    <td align="center" valign="middle" ><?php echo $rows['sotietlithuyet']+$lophp->soTietTHQuyChuanTheoKH(); ?></td>

    <td align="center" valign="middle" ><?php echo $lophp->tongSoTietDaDay();?></td>
    <td align="center" valign="middle" ><?php echo $lophp->soTietTHQuyChuanTT();?></td>
    <td align="center" valign="middle" ><?php echo $lophp->tongSoTietDaDay() + $lophp->soTietTHQuyChuanTT();?></td>
    <td align="center" valign="middle" ><?php echo $rows['sotietlithuyet']-$lophp->tongSoTietDaDay();?></td>
    <td align="center" valign="middle" ><?php echo $lophp->soTietTHQuyChuanTheoKH() - $lophp->soTietTHQuyChuanTT();?></td>
    <td align="center" valign="middle" ><?php echo ($rows['sotietlithuyet']+$lophp->soTietTHQuyChuanTheoKH())-($lophp->tongSoTietDaDay() + $lophp->soTietTHQuyChuanTT()); ?></td>
    <td align="left" valign="middle" >
		<?php
			$j=0;
			$num = mysql_num_rows($resultdsnhomth);
			if ($num>0) echo "Chia làm ".$num." nhóm";
			while ($rowsdsnhomth = mysql_fetch_array($resultdsnhomth)){
				$j++;
				echo "-"."Nhóm ".$j.": ".$rowsdsnhomth['siso']." SV";
			}
		?>	</td>
  </tr>
  <?php
		}
	}
	?>
</table>
<br/>
<table width="100%" border="0" align="center">
  <tr>
    <td width="50%" align="center"><b>Người thực hiện ký tên:</b></td>
    <td width="50%" align="center"><b>Họ và tên:</b> </td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td align="center"><b>Lãnh đạo bộ môn ký tên:</b> </td>
    <td align="center"><b>Họ và tên: </b></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>

</body>
</html>
